package com.example.Annocation.profile;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Description TODO
 * @Date 2024/5/14 15:45
 * @Created by houjunfeng
 */
public class ProfileTest {
    //1.   spring.profiles.active=test
    @Test
    public void test() {

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(ProfileConfiguration.class);
        String[] students = annotationConfigApplicationContext.getBeanDefinitionNames();
        for(String s:students){
            System.out.println(s);
        }
    }


    //2.用代码方式设置生效
    @Test
    public void devTest() {

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.getEnvironment().setActiveProfiles("dev");
        annotationConfigApplicationContext.register(ProfileConfiguration.class);
        annotationConfigApplicationContext.refresh();
        String[] students = annotationConfigApplicationContext.getBeanDefinitionNames();
        for(String s:students){
            System.out.println(s);
        }
    }

    @Test
    public void test3() {

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(ProfileConfiguration.class);
        String[] students = annotationConfigApplicationContext.getBeanDefinitionNames();
        for(String s:students){
            System.out.println(s);
        }
    }
}
